Analysis of World Heritage Sinharaja Rainforest, Sri Lanka - Moja Global 2022 Contribution

by Thushari Pahalage

I have selected Sinharaja Rain forest, in southwestern Sri Lanka. Sinharaja Rain Forest is a Biodiversity Hotspot in Sri Lanka's Sabaragamu and Southern provinces, located in the south west lowland wet zone. It is the last remaining primary tropical rain forest in the country. Due to human activities and changing temperatures, the World Heritage Sinharaja Rainforest in Sri Lanka is generating headlines about its forest cover. According to various resources, a scientific analysis has yet to be conducted on the connected issues regarding Sinharaja. The forest reserve is located between 60 21' and 60 26' north latitude and 800 21' and 800 34' east longitude, and borders the Sri Lankan districts of Rathnapura, Galle, and Matara. In 1978, UNESCO designated Sinharaja forest as a biosphere reserve. As a home to unique and endangered species, It is an excellent location for studying biological evolution. > >

Reference: Hanle J, Singhakumara BMP and Ashton MS (2021) Complex Small-Holder Agriculture in Rainforest Buffer Zone, Sri Lanka, Supports Endemic Birds. Front. Ecol. Evol. 9:608434. doi: 10.3389/fevo.2021.608434 >

> Western Ghats, Sri Lanka:

The geology, climate, and evolutionary history of the Western Ghats in southwestern India and the highlands of south-western Sri Lanka, separated by 400 kilometres, are strikingly similar. They form one of the 34 global biodiversity hotspots that is one of the most densely populated.

> > Reference: https://www.cepf.net/sites/default/files/western-ghats-sri-lanka-fact-sheet.pdf

Visit-Sinharaja-Forest-Reserve-Sri-lnaka.jpg

Local conditions:

Climate-With temperatures ranging from 19°C to 34°C, high humidity, and an average annual precipitation of around 4,500mm, Sinharaja has a hot and humid environment typical of tropical rainforests.

Ecosystem classification- Sri Lanka is home to 830 endemic species, of which 217 trees and woody climbers are found in the low land wet zone.

Age- During the Jurassic period, the rainforest most likely formed (from 200 million years to 145 million years ago).

Flora- At least 139 indigenous plant species can be found in Sinharaja's two main types of forest: Dipterocarpus remains in the valleys and lower slopes, and secondary forest and scrub where the original forest cover has been removed. Sixteen of the property's indigenous plant species are rare, including the endemic palms Loxococcus rupicola and Atalantia rotundifolia.

Endemic species- The biodiverse rainforests of Sinharaja protect 830 endemic plant and animal species, including all but two of the 33 bird species unique to the island.

Reference:https://whc.unesco.org/en/list/405/ https://en.wikipedia.org/wiki/Sinharaja_Forest_Reserve#:~:text=The%20rainforest%20likely%20formed%20during,88%2C960%20acres%2F360%20km%C2%B2)

> Moja Global Land sector Datasets analysis(observations and key takeaways):

> The Data was analyzed under five main categories as provided by the https://github.com/moja-global/Land_Sector_Datasets repository referring to the example by @David Guevara-Apaza - https://github.com/yodavo/moja-global-analysis/tree/main/2021-08_Contribution-Outreachy.

Administrative: The forest is located in Sri Lanka's Sabaragamuwa and Southern provinces. The analysis indicates the Sinharaja Rainforest as an important part of the Bio diversity hotspot, Western Ghats and Sri Lanka. The Western Ghats are an internationally acknowledged location of tremendous worldwide importance for biological variety conservation. > Bioclimatic&EcologicalZones: The forest falls ghr western ghats, a bio diversity hotspot of Asian region. It is typically considered as a tropical rainforest and can be described either as a Tropical Lowland Rain Forest or Tropical Wet Evergreen Forest. According to the Moja Global data the forest falls under tropical dry, moist, and rain forest regions.(section 2) > Climate: Located in south-west Sri Lanka, Sinharaja is considered to be primary a tropical rainforest. According to the Moja Global Analysis the region falls under polar moist and boreal dry regions. *Not Accurate > LandCover:The forest area has not grown over the years(due to deforestration) other than the planted crops.(palm and tinder) > Soil: The area is highly concerntrated with acrisols and lixisols.

In [ ]:
# install and import condalab
!pip install -q condacolab 
import condacolab
condacolab.install()
✨🍰✨ Everything looks OK!
In [ ]:
# install geopandas
!pip install geopandas
import geopandas as gpd
Requirement already satisfied: geopandas in /usr/local/lib/python3.7/site-packages (0.10.2)
Requirement already satisfied: pandas>=0.25.0 in /usr/local/lib/python3.7/site-packages (from geopandas) (1.3.5)
Requirement already satisfied: shapely>=1.6 in /usr/local/lib/python3.7/site-packages (from geopandas) (1.8.1.post1)
Requirement already satisfied: fiona>=1.8 in /usr/local/lib/python3.7/site-packages (from geopandas) (1.8.21)
Requirement already satisfied: pyproj>=2.2.0 in /usr/local/lib/python3.7/site-packages (from geopandas) (3.2.1)
Requirement already satisfied: munch in /usr/local/lib/python3.7/site-packages (from fiona>=1.8->geopandas) (2.5.0)
Requirement already satisfied: cligj>=0.5 in /usr/local/lib/python3.7/site-packages (from fiona>=1.8->geopandas) (0.7.2)
Requirement already satisfied: setuptools in /usr/local/lib/python3.7/site-packages (from fiona>=1.8->geopandas) (49.6.0.post20210108)
Requirement already satisfied: certifi in /usr/local/lib/python3.7/site-packages (from fiona>=1.8->geopandas) (2020.12.5)
Requirement already satisfied: six>=1.7 in /usr/local/lib/python3.7/site-packages (from fiona>=1.8->geopandas) (1.15.0)
Requirement already satisfied: attrs>=17 in /usr/local/lib/python3.7/site-packages (from fiona>=1.8->geopandas) (21.4.0)
Requirement already satisfied: click>=4.0 in /usr/local/lib/python3.7/site-packages (from fiona>=1.8->geopandas) (8.1.2)
Requirement already satisfied: click-plugins>=1.0 in /usr/local/lib/python3.7/site-packages (from fiona>=1.8->geopandas) (1.1.1)
Requirement already satisfied: importlib-metadata in /usr/local/lib/python3.7/site-packages (from click>=4.0->fiona>=1.8->geopandas) (4.11.3)
Requirement already satisfied: pytz>=2017.3 in /usr/local/lib/python3.7/site-packages (from pandas>=0.25.0->geopandas) (2022.1)
Requirement already satisfied: python-dateutil>=2.7.3 in /usr/local/lib/python3.7/site-packages (from pandas>=0.25.0->geopandas) (2.8.2)
Requirement already satisfied: numpy>=1.17.3 in /usr/local/lib/python3.7/site-packages (from pandas>=0.25.0->geopandas) (1.21.5)
Requirement already satisfied: zipp>=0.5 in /usr/local/lib/python3.7/site-packages (from importlib-metadata->click>=4.0->fiona>=1.8->geopandas) (3.7.0)
Requirement already satisfied: typing-extensions>=3.6.4 in /usr/local/lib/python3.7/site-packages (from importlib-metadata->click>=4.0->fiona>=1.8->geopandas) (4.1.1)
In [ ]:
# for download and decompress the dataset
import os, zipfile, glob, io, requests

# for SIG and spatial info management
from shapely.geometry import Polygon, shape

# for SIG and spatial visualization
import folium
from folium import Choropleth
from folium.plugins import HeatMap

# for dataframes and numerical info management
import numpy as np
import pandas as pd

# for plot and graphs
import matplotlib.pyplot as plt
#import seaborn as sns

# Ignore warning about missing/empty geometries
import warnings
warnings.filterwarnings('ignore', 'GeoSeries.notna', UserWarning)
plt.rcParams.update({'figure.max_open_warning': 0})
In [ ]:
# fetching from the repo
! wget https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/110m/cultural/ne_110m_admin_0_countries.zip

# importing the data
world_df = gpd.read_file("ne_110m_admin_0_countries.zip")
world_df.to_crs(epsg=4326, inplace=True)

# also the dataset is huge (162 features), so it need cleaning.
world_df = world_df[['CONTINENT','NAME_LONG', 'POP_EST', 'POP_YEAR', 'geometry']]
world_df.columns = world_df.columns.str.lower()

# features for plot
world_df['centroid'] = world_df.geometry.centroid # adding centroid for plotting names in the map
--2022-04-02 16:45:58--  https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/110m/cultural/ne_110m_admin_0_countries.zip
Resolving www.naturalearthdata.com (www.naturalearthdata.com)... 50.87.253.14
Connecting to www.naturalearthdata.com (www.naturalearthdata.com)|50.87.253.14|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://naciscdn.org/naturalearth/110m/cultural/ne_110m_admin_0_countries.zip [following]
--2022-04-02 16:45:58--  https://naciscdn.org/naturalearth/110m/cultural/ne_110m_admin_0_countries.zip
Resolving naciscdn.org (naciscdn.org)... 52.84.125.6, 52.84.125.112, 52.84.125.91, ...
Connecting to naciscdn.org (naciscdn.org)|52.84.125.6|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 210247 (205K) [application/zip]
Saving to: ‘ne_110m_admin_0_countries.zip.2’

ne_110m_admin_0_cou 100%[===================>] 205.32K  --.-KB/s    in 0.03s   

2022-04-02 16:45:58 (6.63 MB/s) - ‘ne_110m_admin_0_countries.zip.2’ saved [210247/210247]

/usr/local/lib/python3.7/dist-packages/ipykernel_launcher.py:13: UserWarning: Geometry is in a geographic CRS. Results from 'centroid' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation.

  del sys.path[0]

1.ADMINISTRATIVE BOUNDARIES by Country, Continent, Province, GEZ, WSR

In [ ]:
# Plotting the map
ax = world_df.plot(figsize=(30,15), column= 'name_long', cmap= 'tab10', 
                   edgecolor= 'black', legend= True, 
                   legend_kwds={'loc': 'center left', 'ncol': 4, 'bbox_to_anchor':(1,0.5)})
ax.set_title('WORLD MAP\nView by Countries', fontsize=20)
plt.show()
In [ ]:
# Plotting the map
ax = world_df.plot(figsize=(30,15), column= 'continent', cmap= 'tab10', 
                   edgecolor= 'grey', legend= True, 
                   legend_kwds={'loc': 'center left'})#, 'ncol': 3, 'bbox_to_anchor':(1,0.5)})
ax.set_title('WORLD MAP\nView by Continents', fontsize=20)


plt.show()
In [ ]:
# (filtered on the CONTINENT feature) using pandas like dataframe management
asia_df = world_df.loc[world_df.continent == 'Asia',]

# fixing data
asia_df = asia_df.reset_index(drop=True)

# features for plot
asia_df['popu'] = asia_df['pop_est'] / 1e6 # get the population in millions
# Plotting the map
ax = asia_df.plot(figsize=(10,15), column= 'name_long', cmap= 'tab10', 
                           edgecolor= 'black')
ax.set_title('Asia\n', fontsize=20)

# names in the map
props = dict(boxstyle='round', facecolor='linen', alpha=1)
for point in asia_df.iterrows():
  ax.text(point[1]['centroid'].x,
          point[1]['centroid'].y,
          point[1]['name_long'],
          horizontalalignment='center',
          fontsize=10,
          bbox=props)
  
# ax.axis('off') # for removing the grid
plt.show()
In [ ]:
#  using pandas like dataframe management
sl_df = world_df.loc[world_df.name_long == 'Sri Lanka',]
sl_df
Out[ ]:
continent name_long pop_est pop_year geometry centroid
138 Asia Sri Lanka 21803000.0 2019 POLYGON ((81.78796 7.52306, 81.63732 6.48178, ... POINT (80.66724 7.70053)
In [ ]:
# Sri lanka province boundary dataset
boundary1 = 'https://datasets.mojaglobal.workers.dev/0:/Administrative/Boundaries/Level4%20by%20State/LKA/LKA_ALL_states.json'

# download the data with request
boundary1_req = requests.get(boundary1).content

# load the json with geopandas and set crs
boundary_df = gpd.read_file(io.StringIO(boundary1_req.decode('utf-8')))
boundary_df = boundary_df[['name', 'geometry']]

boundary_df.to_crs(5389, inplace=True)
boundary_df.to_crs(4326, inplace=True)

# Plotting the map
ax = boundary_df.plot(figsize=(15,10), color= 'antiquewhite', edgecolor= 'black')
ax.set_title('ADMINISTRATIVE BOUNDARIES IN SRI LANKA based on Provinces\n', fontsize=20)
plt.show()
In [ ]:
# Sri Lanka boundary dataset based on Global Economic Zone
boundary1 = 'https://datasets.mojaglobal.workers.dev/0:/Administrative/Boundaries/Level4%20by%20State/LKA/LKA_ALL_states_GEZ.json'

# download the data with request
boundary1_req = requests.get(boundary1).content

# load the json with geopandas and set crs
boundary_df = gpd.read_file(io.StringIO(boundary1_req.decode('utf-8')))
boundary_df = boundary_df[['name', 'geometry']]

boundary_df.to_crs(5389, inplace=True)
boundary_df.to_crs(4326, inplace=True) 

# Plotting the map
ax = boundary_df.plot(figsize=(15,10), color= 'aqua', edgecolor= 'black')
ax.set_title('ADMINISTRATIVE BOUNDARIES IN SRI LANKA based on Global Economic Zone\n', fontsize=30)
plt.show()
In [ ]:
# Plotting Sri Lanka in Asia
ax = asia_df.plot(figsize=(20,25), color= 'brown', edgecolor= 'white')
boundary_df.plot(ax=ax, color='green', edgecolor='white')
ax.set_title('SRI LANKA LOCATION IN ASIA\n', fontsize=20)

plt.show()
In [ ]:
# SL boundary dataset based on World Soil Resources
boundary1 = 'https://datasets.mojaglobal.workers.dev/0:/Administrative/Boundaries/Level4%20by%20State/LKA/LKA_ALL_states_WSR.json'

# download the data with request
boundary1_req = requests.get(boundary1).content

# load the json with geopandas and set crs
boundary_df = gpd.read_file(io.StringIO(boundary1_req.decode('utf-8')))
boundary_df = boundary_df[['name', 'geometry']]

# fix the georeference! the map seems to be cliped from a bad reference
boundary_df.to_crs(5389, inplace=True)
boundary_df.to_crs(4326, inplace=True) # now is WGS84 again!

# Plotting the map
ax = boundary_df.plot(figsize=(15,10), color= 'yellow', edgecolor= 'black')
ax.set_title('ADMINISTRATIVE BOUNDARIES IN SRI LANKA based on World Soil Resources\n', fontsize=30)
plt.show()
In [ ]:
# SL boundary Sabaragamuwa Province dataset
boundary1 = 'https://datasets.mojaglobal.workers.dev/0:/Administrative/Boundaries/Level4%20by%20State/LKA/LKA_AL4_Sabaragamuwa%20Province.json'

# download the data with request
boundary1_req = requests.get(boundary1).content

# load the json with geopandas and set crs
boundary_df = gpd.read_file(io.StringIO(boundary1_req.decode('utf-8')))
boundary_df = boundary_df[['name', 'geometry']]


boundary_df.to_crs(5389, inplace=True)
boundary_df.to_crs(4326, inplace=True) 

# Plotting the map
ax = boundary_df.plot(figsize=(15,10), color= 'antiquewhite', edgecolor= 'black')
ax.set_title('ADMINISTRATIVE BOUNDARIES IN Sri Lanka:Sabaragamuwa Province\n', fontsize=20)
plt.show()

Selected Provinces for review: Sabaragamuwa and southern(covering Sinharaja Rain forest)

In [ ]:
# Provinces dataset
Sab = 'https://datasets.mojaglobal.workers.dev/0:/Administrative/Boundaries/Level4%20by%20State/LKA/LKA_AL4_Sabaragamuwa%20Province.json'
Sou = 'https://datasets.mojaglobal.workers.dev/0:/Administrative/Boundaries/Level4%20by%20State/LKA/LKA_AL4_Southern%20Province.json'

# download the data with request
Sab_req = requests.get(Sab).content
Sou_req = requests.get(Sou).content

# load the json with geopandas and set crs
SabBoundary_df = gpd.read_file(io.StringIO(Sab_req.decode('utf-8')))
SabBoundary_df = SabBoundary_df[['name', 'geometry']]
SabBoundary_df.set_crs(epsg=4326, inplace=True)
SouBoundary_df = gpd.read_file(io.StringIO(Sou_req.decode('utf-8')))
SouBoundary_df = SouBoundary_df[['name', 'geometry']]
SouBoundary_df.set_crs(epsg=4326, inplace=True)

# fix the georeference! the map seems to be cliped from a bad reference
SabBoundary_df.to_crs(5389, inplace=True)
SabBoundary_df.to_crs(4326, inplace=True) 
SouBoundary_df.to_crs(5389, inplace=True)
SouBoundary_df.to_crs(4326, inplace=True)


print('Sabaragamuwa dataset has %2d rows and %2d columns' %(SabBoundary_df.shape[0], SabBoundary_df.shape[1]))
print('Southern has %2d rows and %2d columns' %(SouBoundary_df.shape[0], SouBoundary_df.shape[1]))
Sabaragamuwa dataset has  1 rows and  2 columns
Southern has  1 rows and  2 columns
In [ ]:
# Using pandas to concatenate the dataframes. This is so cool!
regionsBoundary_df = pd.concat([SabBoundary_df, SouBoundary_df], ignore_index=True)

# features for plot
regionsBoundary_df['centroid'] = regionsBoundary_df.geometry.centroid # adding centroid for plotting names in the map
/usr/local/lib/python3.7/dist-packages/ipykernel_launcher.py:5: UserWarning: Geometry is in a geographic CRS. Results from 'centroid' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation.

  """
In [ ]:
# Plotting in the maps
fig, axes = plt.subplots(1,3, figsize=(20,50))

# first map axes[0]
axes[0].set_title('SRI LANKA\n', fontsize=20)
boundary_df.plot(ax=axes[0], color='orangered', edgecolor='black')
regionsBoundary_df.plot(ax=axes[0], column='name', cmap='Set1', edgecolor='black')
# names in the map
props = dict(boxstyle='round', facecolor='linen', alpha=1)
for point in regionsBoundary_df.iterrows():
  axes[0].text(point[1]['centroid'].x,
          point[1]['centroid'].y,
          point[1]['name'],
          horizontalalignment='center',
          fontsize=10,
          bbox=props)

# second map axes[1]
axes[1].set_title('Sabaragamuwa\n', fontsize=20)
SabBoundary_df.plot(ax=axes[1], color='red', edgecolor='black')

# third map axes[2]
axes[2].set_title('Southern\n', fontsize=20)
SouBoundary_df.plot(ax=axes[2], color='grey', edgecolor='black')

plt.show()

2.Biodiversity Hotspots by Country, Continent, Province

In [ ]:
# Biodiversity Hotspots dataset
bioHot = 'https://datasets.mojaglobal.workers.dev/0:/Bioclimatic&EcologicalZones/CI_BiodiversityHotspots.geojson'

# download the data with request
bioHot_req = requests.get(bioHot).content

# load the json with geopandas
bioHot_df = gpd.read_file(io.StringIO(bioHot_req.decode('utf-8')))
bioHot_df.set_crs(epsg=4326, inplace=True)

# fixing the data: standardizing column names
bioHot_df.columns = bioHot_df.columns.str.lower()

print('The Biodiversity Hotspots dataset has %2d rows and %2d columns' %(bioHot_df.shape[0], bioHot_df.shape[1]))
The Biodiversity Hotspots dataset has 53 rows and  6 columns
In [ ]:
# Plotting the map
ax = world_df.plot(figsize=(30,15), color='none', edgecolor='grey', alpha=0.3)
bioHot_df.plot(ax = ax, column= 'type', cmap= 'tab10', edgecolor= 'black', legend= True, 
                   legend_kwds={'loc': 'lower center', 'ncol': 2})
ax.set_title('WORLD BIODIVERSITY HOTSPOTS\nView by Hotspot Type', fontsize=20)
plt.show()
In [ ]:
# Plotting the map
ax = world_df.plot(figsize=(30,15), color='none', edgecolor='grey', alpha=0.3)
bioHot_df.plot(ax = ax, column= 'name', cmap= 'tab10', edgecolor= 'black', legend= True, 
                   legend_kwds={'loc': 'lower left', 'ncol': 3})
ax.set_title('WORLD BIODIVERSITY HOTSPOTS\nView by Hotspot Name', fontsize=20)
plt.show()
In [ ]:
pip install rtree
Requirement already satisfied: rtree in /usr/local/lib/python3.7/site-packages (0.9.7)
In [ ]:
# creating dataframe
asiaBioHot_df = bioHot_df.clip(asia_df)
asiaBioHot_df = asiaBioHot_df.reset_index(drop=True)
In [ ]:
# Plotting in the maps
fig, axes = plt.subplots(1,2, figsize=(20,50))

# first map axes[0]
axes[0].set_title('ASIA BIODIVERSITY HOTSPOTS\nView by Hostspot Name', fontsize=25)
asia_df.plot(ax=axes[0], color='none', edgecolor='grey', alpha=0.3)
asiaBioHot_df.plot(ax=axes[0], column = 'name', cmap='tab20', legend= True, 
                  legend_kwds={'loc': 'lower right'})

# second map axes[1]
axes[1].set_title('ASIA BIODIVERSITY HOTSPOTS\nView by Hostspot Type', fontsize=25)
asia_df.plot(ax=axes[1], color='none', edgecolor='grey', alpha=0.3)
asiaBioHot_df.plot(ax=axes[1], column = 'type', cmap='tab20', legend= True, 
                  legend_kwds={'loc': 'lower right'})

plt.show()
In [ ]:
# creating dataframe
SLBioHot_df= bioHot_df.clip(boundary_df)
SLBioHot_df = SLBioHot_df.reset_index(drop=True)
In [ ]:
# Plotting in the maps
fig, axes = plt.subplots(1,2, figsize=(20,50))

# first map axes[0]
axes[0].set_title('SRI LANKA BIODIVERSITY HOTSPOTS\nView by Hostspot Name', fontsize=25)
boundary_df.plot(ax=axes[0], color='none', edgecolor='grey', alpha=0.3)
SLBioHot_df.plot(ax=axes[0], column = 'name', cmap='Set1', edgecolor='black', legend= True, 
                  legend_kwds={'loc': 'lower left'})

# second map axes[1]
axes[1].set_title('SRI LANKA BIODIVERSITY HOTSPOTS\nView by Hostspot Type', fontsize=25)
boundary_df.plot(ax=axes[1], color='none', edgecolor='grey', alpha=0.3)
SLBioHot_df.plot(ax=axes[1], column = 'type', cmap='tab20', edgecolor='black', legend= True, 
                  legend_kwds={'loc': 'lower left'})

plt.show()
In [ ]:
# creating dataframe
SouBioHot_df = bioHot_df.clip(SouBoundary_df)
SouBioHot_df = SouBioHot_df.reset_index(drop=True)
SabBioHot_df = bioHot_df.clip(SabBoundary_df)
SabBioHot_df = SabBioHot_df.reset_index(drop=True)
In [ ]:
# Using pandas to concatenate the dataframes.
regionsBioHot_df = pd.concat([SabBioHot_df, SouBioHot_df], ignore_index=True)
In [ ]:
# Plotting in the maps
fig, axes = plt.subplots(1,3, figsize=(20,50))

# first map axes[0]
axes[0].set_title('BIODIVERSITY HOTSPOTS - REGION\nView by Hotspot Name', fontsize=20)
boundary_df.plot(ax=axes[0], color='azure', edgecolor='black')
regionsBoundary_df.plot(ax=axes[0], color='none', edgecolor='grey',  alpha=0.4)
regionsBioHot_df.plot(ax=axes[0], column='name', cmap='Set1', edgecolor='black',
                    legend=True, legend_kwds={'loc': 'lower left'})

# second map axes[1]
axes[1].set_title('BIODIVERSITY HOTSPOTS IN Southern\nView by Hotspot Name', fontsize=20)
SouBoundary_df.plot(ax=axes[1], color='none', edgecolor='grey',  alpha=0.4)
SouBioHot_df.plot(ax=axes[1], column='name', cmap='Set2', edgecolor='black',
                  legend=True, legend_kwds={'loc': 'lower left'})

# third map axes[2]
axes[2].set_title('BIODIVERSITY HOTSPOTS\nIN Sabaragamuwa\nView by Hotspot Name', fontsize=20)
SabBoundary_df.plot(ax=axes[2], color='none', edgecolor='grey',  alpha=0.4)
SabBioHot_df.plot(ax=axes[2], column='name', cmap='Set3', edgecolor='black',
                  legend=True, legend_kwds={'loc': 'upper right'})

plt.show()

2.2 Bioclimatic and Ecological Zones

In [ ]:
# Bioclimatic and Ecological Zones dataset
bioEco = 'https://datasets.mojaglobal.workers.dev/0:/Bioclimatic&EcologicalZones/Global_Ecological_Zone_GEZ/GlobalEcologicalZone_GEZFAO2010.json'

# download the data with request
bioEco_req = requests.get(bioEco).content

# load the json with geopandas
bioEco_df = gpd.read_file(io.StringIO(bioEco_req.decode('utf-8')))
bioEco_df.set_crs(epsg=4326, inplace=True)

# fixing the data: standardizing column names
bioEco_df.columns = bioEco_df.columns.str.lower()

print('The Bioclimatic and Ecological Zones dataset has %2d rows and %2d columns' %(bioEco_df.shape[0], bioEco_df.shape[1]))
The Bioclimatic and Ecological Zones dataset has 16 rows and  4 columns
In [ ]:
# Plotting the map
ax = world_df.plot(figsize=(30,15), color='none', edgecolor='grey', alpha=0.2)
bioEco_df.plot(ax =ax, column= 'gez_name', cmap= 'tab20', legend= True, 
                  legend_kwds={'loc': 'center left', 'ncol': 2})
ax.set_title('BIOCLIMATIC AND ECOLOGICAL ZONES OF THE WORLD\n', fontsize=20)
plt.show()
In [ ]:
# creating dataframe
asiabioEco_df = bioEco_df.clip(asia_df)
asiabioEco_df = asiabioEco_df.reset_index(drop=True)
In [ ]:
# Plotting in the maps
ax = asia_df.plot(figsize=(10,15), color='none', edgecolor='grey', alpha=0.3)
asiabioEco_df.plot(ax=ax, column = 'gez_name', cmap='tab20', legend= True, 
                  legend_kwds={'loc': 'lower right'})
ax.set_title('BIOCLIMATIC AND ECOLOGICAL ZONES\nOF Asia', fontsize=25)

plt.show()
In [ ]:
# SL dataset
SLbioEco = 'https://datasets.mojaglobal.workers.dev/0:/Bioclimatic&EcologicalZones/Global_Ecological_Zone_GEZ/byCountry/LKA_AL2_Sri%20Lanka_GEZ.json'

# download the data with request
SLbioEco_req = requests.get(SLbioEco).content

# load the json with geopandas
SLbioEco_df = gpd.read_file(io.StringIO(SLbioEco_req.decode('utf-8')))

# fix the georeference! the map seems to be cliped from a bad reference
SLbioEco_df.to_crs(5389, inplace=True)
SLbioEco_df.to_crs(4326, inplace=True)

# fixing the data: standardizing column names
bioEco_df.columns = bioEco_df.columns.str.lower()

print('SRI LANKA Bioclimatic an Ecological Zones has %2d rows and %2d columns' %(SLbioEco_df.shape[0], SLbioEco_df.shape[1]))
SRI LANKA Bioclimatic an Ecological Zones has  4 rows and  8 columns
In [ ]:
# plotting the map
ax = SLbioEco_df.plot(figsize = (10,15), column = 'gez_name',
                  edgecolor='black', cmap='tab20', legend= True, 
                  legend_kwds= {'loc': 'lower left'})
ax.set_title('BIOCLIMATIC AND ECOLOGICAL ZONES\nOF SRI LANKA', fontsize=20)
plt.show()
In [ ]:
# state  dataset
SabBioEco = 'https://datasets.mojaglobal.workers.dev/0:/Administrative/Boundaries/Level4%20by%20State/LKA/LKA_AL4_Sabaragamuwa%20Province_GEZ.json'
SouBioEco = 'https://datasets.mojaglobal.workers.dev/0:/Administrative/Boundaries/Level4%20by%20State/LKA/LKA_AL4_Southern%20Province_GEZ.json'

# download the data with request
SabBioEco_req = requests.get(SabBioEco).content
SouBioEco_req = requests.get(SouBioEco).content

# load the json with geopandas and set crs
SabBioEco_df = gpd.read_file(io.StringIO(SabBioEco_req.decode('utf-8')))
SouBioEco_df = gpd.read_file(io.StringIO(SouBioEco_req.decode('utf-8')))

# fix the georeference! the map seems to be cliped from a bad reference
SabBioEco_df.to_crs(5389, inplace=True)
SabBioEco_df.to_crs(4326, inplace=True)
SouBioEco_df.to_crs(5389, inplace=True)
SouBioEco_df.to_crs(4326, inplace=True)

# fixing the data, standardizing column names
SouBioEco_df.columns = SouBioEco_df.columns.str.lower()
SabBioEco_df.columns = SabBioEco_df.columns.str.lower()

print('Sabaragamuwa dataset has %2d rows and %2d columns' %(SabBioEco_df.shape[0], SabBioEco_df.shape[1]))
print('Southern dataset has %2d rows and %2d columns' %(SouBioEco_df.shape[0], SouBioEco_df.shape[1]))
Sabaragamuwa dataset has  3 rows and  8 columns
Southern dataset has  3 rows and  8 columns
In [ ]:
# Using pandas to concatenate the dataframes.
regionsEcoHot_df = pd.concat([SabBioEco_df, SouBioEco_df], ignore_index=True)

# Plotting in the maps
fig, axes = plt.subplots(1,3, figsize=(20,50))

# first map axes[0]
axes[0].set_title('BIOCLIMATIC AND ECOLOGICAL\nZONES OF SRI LANKA\n', fontsize=20)
boundary_df.plot(ax=axes[0], color='azure', edgecolor='black')
regionsEcoHot_df.plot(ax=axes[0], column='gez_name', cmap='tab20c', 
                         edgecolor= 'black', legend=True, legend_kwds={'loc': 'lower left'})

# second map axes[1]
axes[1].set_title('BIOCLIMATIC AND ECOLOGICAL\nZONES OF Southern\n', fontsize=20)
SouBioEco_df.plot(ax=axes[1], column='gez_name', cmap='tab20c', 
                         edgecolor= 'black', legend=True, legend_kwds={'loc': 'lower left'})

# third map axes[2]
axes[2].set_title('BIOCLIMATIC AND ECOLOGICAL\nZONES OF Sabaragamuwa\n', fontsize=20)
SabBioEco_df.plot(ax=axes[2], column='gez_name', cmap='tab20c', 
                         edgecolor= 'black', legend=True, legend_kwds={'loc': 'best'})

plt.show()
In [ ]:
# All Soil resources dataset
holdrigde = 'https://datasets.mojaglobal.workers.dev/0:/Bioclimatic&EcologicalZones/HoldridgeLifeZones.json'

# download the data with request
holdrigde_req = requests.get(holdrigde).content

# load the json with geopandas and set crs
holdrigde_df = gpd.read_file(io.StringIO(holdrigde_req.decode('utf-8')))
holdrigde_df.set_crs(epsg=4326, inplace=True)

# fixing the data
# standardizing column names
holdrigde_df.columns = holdrigde_df.columns.str.lower()

# removing useles columns or empty labels
holdrigde_df = holdrigde_df.loc[holdrigde_df.desc != ' '] # remove oceans
holdrigde_df = holdrigde_df[['desc', 'geometry','frequency', 'area', 'perimeter']]

print('Global Soil resources dataset has %2d rows and %2d columns.' %(holdrigde_df.shape[0], holdrigde_df.shape[1]))
Global Soil resources dataset has 4710 rows and  5 columns.
In [ ]:
# Plotting in the maps
ax = holdrigde_df.plot(figsize= (30,15), column='desc', edgecolor='black', cmap='tab20c',
             legend=True, legend_kwds={'loc': 'lower left', 'ncol':2})
ax.set_title('WORLD HOLDRIDGE LIFE ZONES\n', fontsize=25)
plt.show()
In [ ]:
# creating dataframe
asiaHoldridge_df = holdrigde_df.clip(asia_df)
asiaHoldridge_df = asiaHoldridge_df.reset_index(drop=True)
In [ ]:
# Plotting in the maps
ax = asiaHoldridge_df.plot(figsize=(10,15), column = 'desc', edgecolor='black', cmap='tab20c',
                                    legend= True, legend_kwds={'loc': 'center left', 'bbox_to_anchor':(1,0.5)})
ax.set_title('HOLDRIDGE LIFE ZONES\nOF Asia', fontsize=25)
plt.show()
In [ ]:
# creating dataframe
SLHoldridge_df = holdrigde_df.clip(boundary_df)
SLHoldridge_df = SLHoldridge_df.reset_index(drop=True)
# Plotting in the maps
ax = SLHoldridge_df.plot(figsize=(10,15), column = 'desc', edgecolor='black', cmap='tab20c',
                                    legend= True, legend_kwds={'loc': 'center left', 'bbox_to_anchor':(1,0.5)})
ax.set_title('HOLDRIDGE LIFE ZONES\nOF SRI LANKA', fontsize=25)
plt.show()
In [ ]:
# creating dataframe
SouHoldridge_df = holdrigde_df.clip(SouBoundary_df)
SouHoldridge_df = SouHoldridge_df.reset_index(drop=True)
Sabholdrigde_df = holdrigde_df.clip(SabBoundary_df)
Sabholdrigde_df = Sabholdrigde_df.reset_index(drop=True)

# Using pandas to concatenate the dataframes.
regionsHoldridge_df = pd.concat([Sabholdrigde_df, SouHoldridge_df], ignore_index=True)
# Plotting in the maps
fig, axes = plt.subplots(1,3, figsize=(35,20))

# first map axes[0]
axes[0].set_title('HOLDRIDGE LIFE ZONES - REGION\n', fontsize=20)
boundary_df.plot(ax=axes[0], color='azure', edgecolor='black')
regionsHoldridge_df.plot(ax=axes[0], column='desc', cmap='Set1', edgecolor='black',
                    legend=True, legend_kwds={'loc': 'lower left'})

# second map axes[1]
axes[1].set_title('HOLDRIDGE LIFE ZONES\nOF Southern', fontsize=20)
SouHoldridge_df.plot(ax=axes[1], column='desc', cmap='Set2', edgecolor='black',
                  legend=True, legend_kwds={'loc': 'lower left'})

# third map axes[2]
axes[2].set_title('HOLDRIDGE LIFE ZONES\nIN Sabaragamuwa', fontsize=20)
Sabholdrigde_df.plot(ax=axes[2], column='desc', cmap='Set3', edgecolor='black',
                  legend=True, legend_kwds={'loc': 'upper right'})
Out[ ]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fac38e2ad50>
In [ ]:
# All Agro Ecological Zones dataset
agroEco = 'https://datasets.mojaglobal.workers.dev/0:/Bioclimatic&EcologicalZones/GAEZ_Global_AgroEcological_Zones/GlobalAgroEcologicalZones_GAEZ.geojson'

# download the data with request
agroEco_req = requests.get(agroEco).content

# load the json with geopandas
agroEco_df = gpd.read_file(io.StringIO(agroEco_req.decode('utf-8')))
agroEco_df.set_crs(epsg=4326, inplace=True)

print('Global Agro Ecological Zones dataset has %2d rows and %2d columns.' %(agroEco_df.shape[0], agroEco_df.shape[1]))
Global Agro Ecological Zones dataset has 116675 rows and  2 columns.
In [ ]:
# fixing the data
values = {'1': 'Wheat', '2': 'Rice', '3': 'Maize', '4': 'Sorghum', '5': 'Millet', 
          '6': 'Other cereals', '7': 'Tubers', '8': 'Roots', '9': 'Sugar beet', 
          '10': 'Sugarcane', '11': 'Pulses', '12': 'Soybean', '13': 'Rape', 
          '14': 'Sunflower', '15': 'Groundnut', '16': 'Oil Palm', '17': 'Olive', 
          '18': 'Cotton', '19': 'Cash 1', '20': 'Vegetables', '21': 'Cash 2', 
          '22': 'Fodder', '23': 'Residual'}

# standardizing column names
agroEco_df.columns = agroEco_df.columns.str.lower()

# renaming class_name
agroEco_df.value = agroEco_df.value.astype('str').replace(values)
In [ ]:
# plotting the map
ax = agroEco_df.plot(figsize = (30,15), column = 'value',
                     legend= True, legend_kwds= {'loc': 'lower left'})
ax.set_title('WORLD AGROECOLOGICAL ZONES MAP\n', fontsize=25)
plt.show()
In [ ]:
# creating dataframe
asiaEco_df = agroEco_df.clip(asia_df)
asiaEco_df = asiaEco_df.reset_index(drop=True)
# Plotting in the maps
ax = asiaEco_df.plot(figsize=(40,55), edgecolor='black', column = 'value', cmap='tab10',
                                    legend= True, legend_kwds={'loc': 'lower right'})
ax.set_title('AGROECOLOGICAL ZONES\nOF ASIA', fontsize=25)
plt.show()
In [ ]:
# creating dataframe
SLagroEco_df = agroEco_df.clip(boundary_df)
SLagroEco_df = SLagroEco_df.reset_index(drop=True)
# Plotting in the maps
ax = SLagroEco_df.plot(figsize=(10,15), edgecolor='black', column = 'value', cmap='tab10',
                                    legend= True, legend_kwds={'loc': 'lower left'})
ax.set_title('AGROECOLOGICAL ZONES\nOF SABARAGAMUWA', fontsize=25)
plt.show()
In [ ]:
# creating dataframe
SouagroEco_df = agroEco_df.clip(SouBoundary_df)
SouagroEco_df = SouagroEco_df.reset_index(drop=True)
SabagroEco_df = agroEco_df.clip(SabBoundary_df)
SabagroEco_df = SabagroEco_df.reset_index(drop=True)

#6.5. Agro ecological zones of of both Provinces
# Using pandas to concatenate the dataframes.
regionsagroEco_df = pd.concat([SabagroEco_df, SouagroEco_df], ignore_index=True)
# Plotting in the maps
fig, axes = plt.subplots(1,3, figsize=(35,20))

# first map axes[0]
axes[0].set_title('AGROECOLOGICAL ZONES - REGION\n', fontsize=20)
boundary_df.plot(ax=axes[0], color='azure', edgecolor='black')
regionsagroEco_df.plot(ax=axes[0], column='value', cmap='Set3', edgecolor='black',
                    legend=True, legend_kwds={'loc': 'lower left'})

# second map axes[1]
axes[1].set_title('AGROECOLOGICAL ZONES\nOF Southern', fontsize=20)
SouagroEco_df.plot(ax=axes[1], column='value', cmap='Set3', edgecolor='black',
                  legend=True, legend_kwds={'loc': 'lower left'})

# third map axes[2]
axes[2].set_title('AGROECOLOGICAL ZONES\nIN Sabaragamuwa', fontsize=20)
SabagroEco_df.plot(ax=axes[2], column='value', cmap='Set3', edgecolor='black',
                  legend=True, legend_kwds={'loc': 'upper right'})
plt.show()

3.Climate Conditions by Country, Continent, Province

In [ ]:
# Climate Zones dataset
climate = 'https://datasets.mojaglobal.workers.dev/0:/Climate/IPCC_ClimateZoneMap_Vector.geojson'

# download the data with request
climate_req = requests.get(climate).content

# load the json with geopandas
climate_df = gpd.read_file(io.StringIO(climate_req.decode('utf-8')))
climate_df.set_crs(epsg=4326, inplace=True)

# standardizing column names
climate_df.columns = climate_df.columns.str.lower()

print('World Climate Zones dataset has %2d rows and %2d columns.' %(climate_df.shape[0], climate_df.shape[1]))
World Climate Zones dataset has 26165 rows and  2 columns.
In [ ]:
# Replacing the data that was in codes
classification =  {'1': 'Tropical montane', '2' : 'Tropical wet', 
                   '3': 'Tropical moist', '4': 'Tropical dry', 
                   '5': 'Warm temperate moist', '6': 'Warm temperate dry',
                   '7': 'Cool temperate moist', '8': 'Cool temperate dry',
                   '9': 'Boreal moist', '10': 'Boreal dry', '11' : 'Polar moist',
                   '12': 'Polar dry'}


# renaming class_name
climate_df.class_name = climate_df.class_name.astype('str').replace(classification)

# removing oceans
climate_df =  climate_df.loc[climate_df.class_name != '0']
In [ ]:
# plotting the map
ax = climate_df.plot(figsize = (30,15), column = 'class_name', legend= True, 
                     legend_kwds= {'loc': 'lower left'})
ax.set_title('WORLD CLIMATE ZONE MAP\n', fontsize=25)
plt.show()
In [ ]:
# creating dataframe
asiaClimate_df = climate_df.clip(asia_df)
asiaClimate_df = asiaClimate_df.reset_index(drop=True)
# Plotting in the maps
ax = asiaClimate_df.plot(figsize=(10,15), edgecolor='black', column = 'class_name', cmap='tab20',
                                    legend= True, legend_kwds={'loc': 'lower right'})
ax.set_title('CLIMATE ZONES\nOF ASIA', fontsize=25)
plt.show()
In [ ]:
# creating dataframe
SLClimate_df = climate_df.clip(boundary_df)
SLClimate_df = SLClimate_df.reset_index(drop=True)
# Plotting in the maps
ax = SLClimate_df.plot(figsize=(10,15), edgecolor='black', column = 'class_name', cmap='tab20',
                                    legend= True, legend_kwds={'loc': 'lower left'})
ax.set_title('CLIMATE ZONES\nOF Sabaragamuwa', fontsize=25)
plt.show()
In [ ]:
# creating dataframe
SouClimate_df = climate_df.clip(SouBoundary_df)
SouClimate_df = SouClimate_df.reset_index(drop=True)
SabClimate_df = climate_df.clip(SabBoundary_df)
SabClimate_df = SabClimate_df.reset_index(drop=True)
In [ ]:
# Using pandas to concatenate the dataframes.
regionsClimate_df = pd.concat([SabClimate_df, SouClimate_df], ignore_index=True)
# Plotting in the maps
fig, axes = plt.subplots(1,3, figsize=(35,20))

# first map axes[0]
axes[0].set_title('CLIMATIC ZONES IN THE REGION\n', fontsize=20)
boundary_df.plot(ax=axes[0], color='azure', edgecolor='black')
regionsClimate_df.plot(ax=axes[0], column='class_name', cmap='Set3_r', edgecolor='black',
                    legend=True, legend_kwds={'loc': 'lower left'})

# second map axes[1]
axes[1].set_title('CLIMATIC ZONES\nIN Southern', fontsize=20)
SouClimate_df.plot(ax=axes[1], column='class_name', cmap='Set3_r', edgecolor='black',
                  legend=True, legend_kwds={'loc': 'lower left'})

# third map axes[2]
axes[2].set_title('CLIMATIC ZONES\nIN Sabaragamuwa', fontsize=20)
SabClimate_df.plot(ax=axes[2], column='class_name', cmap='Set3_r', edgecolor='black',
                  legend=True, legend_kwds={'loc': 'upper right'})
plt.show()
In [ ]:
#9. Koppen-Geiger Climate Changes (1901 - 2100)
# Load the data and prepare the datasets
!wget 'https://datasets.mojaglobal.workers.dev/0:/Climate/KoppenGeiger_ClimateShifts1901_2100/KoppenGeigerClimateShifts.zip'
with zipfile.ZipFile('KoppenGeigerClimateShifts.zip', 'r') as shifts:
  shifts.extractall("shifts")

# remove zip
%rm KoppenGeigerClimateShifts.zip

# path to the folder
files = glob.glob(os.path.join('/content/shifts', '*geojson'))
# Rename and arrange the information
# prepare names
names = [i[16:25]+ '_' + i[26:28] for i in files]  

# prepare the files
files_loaded = [gpd.read_file(f) for f in files]

# merging all the metadata
koppen = list(zip(names, files_loaded))

# print the results
print('%2d dataset were imported for shift in climate Zones.' %(len(koppen)))

# fixing the data, adding abbreviations and koppen-geiger terms

# the Koppen-Geiger system
koppen_abb = {'11': 'Af', '12': 'Am', '13': 'As', '14': 'Aw', '21': 'BWk', 
              '22': 'BWh', '26': 'BSk', '27': 'BSh', '31': 'Cfa', 
              '32': 'Cfb', '33': 'Cfc', '34': 'Csa', '35': 'Csb', 
              '36': 'Csc', '37': 'Cwa', '38': 'Cwb', '39': 'Cwc', 
              '41': 'Dfa', '42': 'Dfb', '43': 'Dfc', '44': 'Dfd', 
              '45': 'Dsa', '46': 'Dsb', '47': 'Dsc', '48': 'Dsd', 
              '49': 'Dwa', '50': 'Dwb', '51': 'Dwc', '52': 'Dwd', 
              '61': 'EF', '62': 'ET', '0': 'NaN'}

koppen_term ={'Af' : 'Tropical rainforest climate', 'Am' : 'Tropical monsoon climate', 
              'As' : 'Tropical savanna climate with dry-summer characteristics', 
              'Aw' : 'Tropical savanna climate with dry-winter characteristics', 
              'BWk' : 'Cold desert climate', 'BWh' : 'Hot desert climate', 
              'BSk' : 'Cold semi-arid climate', 'BSh' : 'Hot semi-arid climate', 
              'Cfa' : 'Humid subtropical climate;', 'Cfb' : 'Temperate oceanic climate', 
              'Cfc' : 'Subpolar oceanic climate', 'Csa' : 'Hot-summer Mediterranean climate', 
              'Csb' : 'Warm-summer Mediterranean climate', 'Csc' : 'Cold-summer Mediterranean climate', 
              'Cwa' : 'Monsoon-influenced humid subtropical climate', 'Cwb' : 'Subtropical highland climate', 
              'Cwc' : 'Cold subtropical highland climate', 'Dfa' : 'Hot-summer humid continental climate', 
              'Dfb' : 'Warm-summer humid continental climate', 'Dfc' : 'Subarctic climate', 
              'Dfd' : 'Extremely cold subarctic climate', 'Dsa' : 'Mediterranean-influenced hot-summer humid continental climate', 
              'Dsb' : 'Mediterranean-influenced warm-summer humid continental climate', 
              'Dsc' : 'Mediterranean-influenced subarctic climate', 'Dsd' : 'Mediterranean-influenced extremely cold subarctic climate', 
              'Dwa' : 'Monsoon-influenced hot-summer humid continental climate', 'Dwb' : 'Monsoon-influenced warm-summer humid continental climate', 
              'Dwc' : 'Monsoon-influenced subarctic climate', 'Dwd' : 'Monsoon-influenced extremely cold subarctic climate', 
              'EF' : 'Ice cap climate', 'ET' : 'Tundra climate'}

# replacing in all the dataframes
for i in koppen:
  name, df = i
  # fixing df, lower columns
  df.columns = df.columns.str.lower()
  # mapping abbreviations
  df['gridcode'] = df['gridcode'].fillna(0) # handle empty
  df['gridcode'] = df['gridcode'].astype(int) # coercing for replace
  df['abb'] = df.gridcode.astype(str).replace(koppen_abb)
  # mappin name
  df['koppen'] = df.abb.replace(koppen_term)
  # selecting columns
  df = df[['abb', 'koppen', 'geometry', 'shape_length', 'shape_area']]
# Plotting function - for horizontal
def plot_shift(df_list):
  font = {'family': 'serif',
          'color':  'darkred',
          'weight': 'normal',
          'size': 30,
          }

  fig, axs = plt.subplots(2,2, figsize=(30, 15), facecolor='w', edgecolor='k')

  for ax, i in zip(axs.ravel(),df_list) :
    name, df = i
    #name correction
    if '_' in name:
      name = name.replace('_', ' in ')

    df.set_crs(epsg=4326, inplace=True)
    df.plot(ax = ax, column='abb', cmap='tab20c',
            legend=True, legend_kwds= {'ncol': 3, 'loc': 'lower left'})
    ax.set_title(str(name), fontdict=font)
  plt.tight_layout()
  plt.show()
# Plotting function - for south america - peru
def plot_shiftv(df_list, legend_loc):
  font = {'family': 'serif',
          'color':  'darkred',
          'weight': 'normal',
          'size': 30,
          }

  fig, axs = plt.subplots(1,4, figsize=(30, 15), facecolor='w', edgecolor='k')

  for ax, i in zip(axs.ravel(),df_list) :
    name, df = i
    #name correction
    if '_' in name:
      name = name.replace('_', ' in ')

    df.set_crs(epsg=4326, inplace=True)
    df.plot(ax = ax, column='koppen', cmap='tab20c',
            legend=True, legend_kwds= {'ncol': 1, 'loc': legend_loc})
    ax.set_title(str(name), fontdict=font)
  plt.tight_layout()
  plt.show()
# Plotting function - for regions
def plot_shift_region(df_list,legend_loc):
  font = {'family': 'serif',
          'color':  'darkred',
          'weight': 'normal',
          'size': 30,
          }

  fig, axs = plt.subplots(2,2, figsize=(15, 15), facecolor='w', edgecolor='k')

  for ax, i in zip(axs.ravel(),df_list) :
    name, df = i
    #name correction
    if '_' in name:
      name = name.replace('_', ' in ')

    df.set_crs(epsg=4326, inplace=True)
    df.plot(ax = ax, column='koppen', cmap='tab20c',
            legend=True, legend_kwds= {'loc': legend_loc})
    ax.set_title(str(name), fontdict=font)
  plt.tight_layout()
  plt.show()
--2022-04-02 16:52:47--  https://datasets.mojaglobal.workers.dev/0:/Climate/KoppenGeiger_ClimateShifts1901_2100/KoppenGeigerClimateShifts.zip
Resolving datasets.mojaglobal.workers.dev (datasets.mojaglobal.workers.dev)... 172.67.201.202, 104.21.60.214, 2606:4700:3035::6815:3cd6, ...
Connecting to datasets.mojaglobal.workers.dev (datasets.mojaglobal.workers.dev)|172.67.201.202|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2872855 (2.7M) [application/x-zip-compressed]
Saving to: ‘KoppenGeigerClimateShifts.zip’

KoppenGeigerClimate 100%[===================>]   2.74M  --.-KB/s    in 0.07s   

2022-04-02 16:52:58 (40.6 MB/s) - ‘KoppenGeigerClimateShifts.zip’ saved [2872855/2872855]

20 dataset were imported for shift in climate Zones.
In [ ]:
# creating a new list for observations geojson (no other code than years)
observations_world = []
for i in koppen:
  name, df = i
  if name[-2:] == 'ge':
    observations_world.append((name[:-3], df))

# sorting the list by year
observations_world = sorted(observations_world, key = lambda x: int(x[0][0:3]))

# plotting variations in observations
plot_shift(observations_world)
In [ ]:
# creating a new list for observations geojson for Asia
observations_asia = []
for i in observations_world:
  name, df = i
  temp = df.clip(asia_df)
  temp = temp.reset_index(drop=True)
  observations_asia.append((name, temp))

# plotting variations in observations
plot_shiftv(observations_asia, 'lower left')
In [ ]:
# creating a new list for observations geojson for Sab
observations_SL = []
for i in observations_world:
  name, df = i
  temp = df.clip(boundary_df)
  temp = temp.reset_index(drop=True)
  observations_SL.append((name, temp))

# plotting variations in observations
plot_shiftv(observations_SL, 'lower left')
In [ ]:
# creating a new list for observations geojson for SAB
observations_region = []
for i in observations_world:
  name, df = i
  temp = df.clip(regionsBoundary_df)
  temp = temp.reset_index(drop=True)
  observations_region.append((name, temp))

# plotting variations in observations
plot_shift_region(observations_region, 'lower left')
In [ ]:
# creating a new list for a1f1
a1f1_world = []
for i in koppen:
  name, df = i
  if name[-2:] == 'A1':
    a1f1_world.append((name +'F1', df))

# sorting the list by year
a1f1_world = sorted(a1f1_world, key = lambda x: int(x[0][0:3]))

# plotting variations in a1f1
plot_shift(a1f1_world)
In [ ]:
# creating a new list for observations geojson for SA
a1f1_southamerica = []
for i in a1f1_world:
  name, df = i
  temp = df.clip(asia_df)
  temp = temp.reset_index(drop=True)
  a1f1_southamerica.append((name, temp))

# plotting variations in observations
plot_shiftv(a1f1_southamerica, 'lower right')
In [ ]:
# creating a new list for observations geojson
a1f1_peru = []
for i in a1f1_world:
  name, df = i
  temp = df.clip(boundary_df)
  temp = temp.reset_index(drop=True)
  a1f1_peru.append((name, temp))

# plotting variations in observations
plot_shiftv(a1f1_peru, 'lower left')
In [ ]:
# creating a new list for observations geojson
a1f1_region = []
for i in a1f1_world:
  name, df = i
  temp = df.clip(regionsBoundary_df)
  temp = temp.reset_index(drop=True)
  a1f1_region.append((name, temp))

# plotting variations in observations
plot_shift_region(a1f1_region, 'lower left')
In [ ]:
# creating a new list for a2
a2_world = []
for i in koppen:
  name, df = i
  if name[-2:] == 'A2':
    a2_world.append((name, df))

# sorting the list by year
a2_world = sorted(a2_world, key = lambda x: int(x[0][0:3]))

# plotting variations in a1f1
plot_shift(a2_world)
In [ ]:
# creating a new list for observations geojson for ASia
a2_southamerica = []
for i in a2_world:
  name, df = i
  temp = df.clip(asia_df)
  temp = temp.reset_index(drop=True)
  a2_southamerica.append((name, temp))

# plotting variations in observations
plot_shiftv(a2_southamerica, 'lower right')
In [ ]:
# creating a new list for observations geojson
a2_SL = []
for i in a2_world:
  name, df = i
  temp = df.clip(boundary_df)
  temp = temp.reset_index(drop=True)
  a2_SL.append((name, temp))

# plotting variations in observations
plot_shiftv(a2_SL, 'lower left')
In [ ]:
# creating a new list for observations geojson
a2_region = []
for i in a2_world:
  name, df = i
  temp = df.clip(regionsBoundary_df)
  temp = temp.reset_index(drop=True)
  a2_region.append((name, temp))

# plotting variations in observations
plot_shift_region(a2_region, 'lower left')
In [ ]:
# creating a new list for b1
b1_world = []
for i in koppen:
  name, df = i
  if name[-2:] == 'B1':
    b1_world.append((name, df))

# sorting the list by year
b1_world = sorted(b1_world, key = lambda x: int(x[0][0:3]))

# plotting variations in a1f1
plot_shift(b1_world)
In [ ]:
# creating a new list for observations geojson for ASIA
b1_asia = []
for i in b1_world:
  name, df = i
  temp = df.clip(asia_df)
  temp = temp.reset_index(drop=True)
  b1_asia.append((name, temp))

# plotting variations in observations
plot_shiftv(b1_asia, 'lower right')
In [ ]:
# creating a new list for observations geojson
b1_SL = []
for i in b1_world:
  name, df = i
  temp = df.clip(boundary_df)
  temp = temp.reset_index(drop=True)
  b1_SL.append((name, temp))

# plotting variations in observations
plot_shiftv(b1_SL, 'lower left')
In [ ]:
# creating a new list for observations geojson
b1_region = []
for i in b1_world:
  name, df = i
  temp = df.clip(regionsBoundary_df)
  temp = temp.reset_index(drop=True)
  b1_region.append((name, temp))

# plotting variations in observations
plot_shift_region(b1_region, 'lower left')
In [ ]:
# creating a new list for b1
b2_world = []
for i in koppen:
  name, df = i
  if name[-2:] == 'B2':
    b2_world.append((name, df))

# sorting the list by year
b2_world = sorted(b2_world, key = lambda x: int(x[0][0:3]))

# plotting variations in a1f1
plot_shift(b2_world)
In [ ]:
# creating a new list for observations geojson for Asia
b2_asia = []
for i in b2_world:
  name, df = i
  temp = df.clip(asia_df)
  temp = temp.reset_index(drop=True)
  b2_asia.append((name, temp))

# plotting variations in observations
plot_shiftv(b2_asia, 'lower right')
In [ ]:
# creating a new list for observations geojson
b2_Sab = []
for i in b2_world:
  name, df = i
  temp = df.clip(boundary_df)
  temp = temp.reset_index(drop=True)
  b2_Sab.append((name, temp))

# plotting variations in observations
plot_shiftv(b2_Sab, 'lower left')
In [ ]:
# creating a new list for observations geojson
b2_region = []
for i in b2_world:
  name, df = i
  temp = df.clip(regionsBoundary_df)
  temp = temp.reset_index(drop=True)
  b2_region.append((name, temp))

# plotting variations in observations
plot_shift_region(b2_region, 'lower left')

4.Land Cover by Country, Continent, Province

In [ ]:
# Sri Lankan Planted Forest dataset
forest = 'https://datasets.mojaglobal.workers.dev/0:/LandCover/Forest/Planted_Forests_SDPT/LKA_Sri%20Lanka_SDPT.json'

# download the data with request
forest_req = requests.get(forest).content

# load the json with geopandas
forest_df = gpd.read_file(io.StringIO(forest_req.decode('utf-8')))
forest_df.to_crs(epsg=4326)

# fixing the data
# removing Unkown data
forest_df = forest_df.replace('Unknown', np.nan)
forest_df = forest_df.replace('n/a', np.nan)

# subseting important variables
forest_df = forest_df.rename(columns = {'size':'size_tree'})
forest_df = forest_df[['species', 'species_simp', 'common_name', 'plant_ag', 
                       'timber_ag','ever_dec', 'conifer_broad', 'hard_soft', 
                       'size_tree', 'year', 'org_name', 'geometry']]

print('Sri Lankan Planted Forest dataset has %2d rows and %2d columns' %(forest_df.shape[0], forest_df.shape[1]))
Sri Lankan Planted Forest dataset has 38 rows and 12 columns
In [ ]:
# Plotting in the maps
fig, axes = plt.subplots(1,4, figsize=(30,50))

# first map axes[0]
axes[0].set_title('PLANTED FOREST IN Sri Lanka\nView by Common Name')
boundary_df.plot(ax=axes[0], color='none', edgecolor='black')
regionsBoundary_df.plot(ax=axes[0], color='none', edgecolor='grey', alpha=0.3)
forest_df.plot(ax=axes[0], column='common_name', edgecolor='black', markersize=15, cmap='Set1', legend=True, legend_kwds={'loc': 'lower left'})

# second map axes[1]
axes[1].set_title('PLANTED FOREST IN Sri Lanka\nView by Timber')
boundary_df.plot(ax=axes[1], color='none', edgecolor='black')
regionsBoundary_df.plot(ax=axes[1], color='none', edgecolor='grey', alpha=0.3)
forest_df.plot(ax=axes[1], column='timber_ag', edgecolor='black', markersize=15, cmap='Set2', legend=True, legend_kwds={'loc': 'lower left'})

# third map axes[2]
axes[3].set_title('PLANTED FOREST IN Sri Lanka\nView by Type of Tree')
boundary_df.plot(ax=axes[3], color='none', edgecolor='black')
regionsBoundary_df.plot(ax=axes[3], color='none', edgecolor='grey', alpha=0.3)
forest_df.plot(ax=axes[3], column='species_simp', edgecolor='black', markersize=15, cmap='Set1_r', legend=True, legend_kwds={'loc': 'lower left'})

# third map axes[2]
axes[2].set_title('PLANTED FOREST IN Sri Lanka\nView by Size')
boundary_df.plot(ax=axes[2], color='none', edgecolor='black')
regionsBoundary_df.plot(ax=axes[2], color='none', edgecolor='grey', alpha=0.3)
forest_df.plot(ax=axes[2], column='size_tree', edgecolor='black', markersize=15, cmap='Set3', legend=True, legend_kwds={'lower left'})



plt.show()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-90-1c2cac241b08> in <module>()
     24 boundary_df.plot(ax=axes[2], color='none', edgecolor='black')
     25 regionsBoundary_df.plot(ax=axes[2], color='none', edgecolor='grey', alpha=0.3)
---> 26 forest_df.plot(ax=axes[2], column='size_tree', edgecolor='black', markersize=15, cmap='Set3', legend=True, legend_kwds={'lower left'})
     27 
     28 

/usr/local/lib/python3.7/site-packages/geopandas/plotting.py in __call__(self, *args, **kwargs)
    948         kind = kwargs.pop("kind", "geo")
    949         if kind == "geo":
--> 950             return plot_dataframe(data, *args, **kwargs)
    951         if kind in self._pandas_kinds:
    952             # Access pandas plots

/usr/local/lib/python3.7/site-packages/geopandas/plotting.py in plot_dataframe(df, column, cmap, color, ax, cax, categorical, legend, scheme, k, vmin, vmax, markersize, figsize, legend_kwds, categories, classification_kwds, missing_kwds, aspect, **style_kwds)
    930                 legend_kwds.setdefault("cax", cax)
    931             else:
--> 932                 legend_kwds.setdefault("ax", ax)
    933 
    934             n_cmap.set_array(np.array([]))

AttributeError: 'set' object has no attribute 'setdefault'
In [ ]:
# creating dataframe
SouForest_df = forest_df.clip(SouBoundary_df)
SouForest_df = SouForest_df.reset_index(drop=True)
SabForest_df = forest_df.clip(SabBoundary_df)
SabForest_df = SabForest_df.reset_index(drop=True)

# Using pandas to concatenate the dataframes.
regionsForest_df = pd.concat([SabForest_df, SouForest_df], ignore_index=True)
# Plotting in the maps
fig, axes = plt.subplots(1,2, figsize=(35,20))

# first map axes[0]
axes[0].set_title('PLANTED FOREST IN REGIONS\nView by Size', fontsize=20)
boundary_df.plot(ax=axes[0], color='azure', edgecolor='black')
regionsBoundary_df.plot(ax=axes[0], color='none', edgecolor='grey', alpha=0.3)
regionsForest_df.plot(ax=axes[0], column='size_tree', cmap='Set3', edgecolor='black')

# second map axes[1]
axes[1].set_title('PLANTED FOREST IN Southern\nView by Size', fontsize=20)
SouBoundary_df.plot(ax=axes[1], color='none', edgecolor='black')
SouForest_df.plot(ax=axes[1], column='size_tree', cmap='Set3', edgecolor='black')
Out[ ]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fac2f352b50>

5.Soil Resources by Country, Continent, Province

In [ ]:
# World Soil resources
soil1 = 'https://datasets.mojaglobal.workers.dev/0:/Soil/World%20Soil%20Resources/World_Soil_Resources_wgs84.geojson'

# download the data with request
soil1_req = requests.get(soil1).content

# load the json with geopandas
soil_df = gpd.read_file(io.StringIO(soil1_req.decode('utf-8')))
soil_df.set_crs(epsg=4326, inplace=True)

# fixing the data: standardizing column names
soil_df.columns = soil_df.columns.str.lower()

print('World Soil resources dataset has %2d rows and %2d columns' %(soil_df.shape[0], soil_df.shape[1]))

# plotting the map
ax = soil_df.plot(figsize = (20,10), column = 'ipcc', cmap='tab20', legend= True, 
                  legend_kwds={'loc': 'lower left', 'ncol': 2})
ax.set_title('WORLD SOIL RESOURCES\n', fontsize=25)
plt.show()
World Soil resources dataset has 33 rows and  3 columns
In [ ]:
# Using geopandas to clip soil_df in the shape of asia_df
asiaSoil_df = soil_df.clip(asia_df)
asiaSoil_df= asiaSoil_df.reset_index(drop=True) # removing index
# plotting the map
ax = asiaSoil_df.plot(figsize = (10,15), column = 'ipcc', cmap='tab20', legend= True, 
                  legend_kwds={'loc': 'lower right'})
ax.set_title('Asia SOIL RESOURCES\n', fontsize=25)
plt.show()
In [ ]:
# SL Soil resources
SLSoil1 = 'https://datasets.mojaglobal.workers.dev/0:/Soil/World%20Soil%20Resources/byCountry/LKA_AL2_Sri%20Lanka_WSR.json'

# download the data with request
SLSoil1_req = requests.get(SLSoil1).content

# load the json with geopandas
SLSoil_df = gpd.read_file(io.StringIO(SLSoil1_req.decode('utf-8')))

# fix the georeference the map seems to be cliped from a bad reference
SLSoil_df.to_crs(5389, inplace=True)
SLSoil_df.to_crs(4326, inplace=True) # now is WGS84

# fixing the data
# standardizing column names
SLSoil_df.columns = SLSoil_df.columns.str.lower()

# drop useless columns
SLSoil_df = SLSoil_df[['sname', 'ipcc', 'geometry']]

print('SRi Lankan Soil resources dataset has %2d rows and %2d columns' %(SLSoil_df.shape[0], SLSoil_df.shape[1]))

# plotting the map
ax = SLSoil_df.plot(figsize = (20,10), column = 'ipcc',
                  edgecolor='black', cmap='tab10', legend= True, 
                  legend_kwds= {'loc': 'lower left'})
ax.set_title('SOIL RESOURCES IN SL\n', fontsize=25)
plt.show()
SRi Lankan Soil resources dataset has  2 rows and  3 columns
In [ ]:
# states
Sab2 = 'https://datasets.mojaglobal.workers.dev/0:/Soil/World%20Soil%20Resources/byStateWSR/LKA/LKA_AL4_Sabaragamuwa%20Province_WSR.json'
Sou2 = 'https://datasets.mojaglobal.workers.dev/0:/Soil/World%20Soil%20Resources/byStateWSR/LKA/LKA_AL4_Southern%20Province_WSR.json'

# download the data with request
Sab2_req = requests.get(Sab2).content
Sou2_req = requests.get(Sou2).content

# load the json with geopandas and set_crs
SabSoil_df = gpd.read_file(io.StringIO(Sab2_req.decode('utf-8')))
SouSoil_df = gpd.read_file(io.StringIO(Sou2_req.decode('utf-8')))

# fix the georeference! the map seems to be cliped from a bad reference
SabSoil_df.to_crs(5389, inplace=True)
SabSoil_df.to_crs(4326, inplace=True) 
SouSoil_df.to_crs(5389, inplace=True)
SouSoil_df.to_crs(4326, inplace=True)

# fixing the data
# standardizing column names
SouSoil_df.columns = SouSoil_df.columns.str.lower()
SabSoil_df.columns = SabSoil_df.columns.str.lower()

# drop useless columns
SabSoil_df = SabSoil_df[['sname', 'ipcc', 'geometry']]
SouSoil_df = SouSoil_df[['sname', 'ipcc', 'geometry']]

print('Sabaragamuwa\'s Soil dataset has %2d rows and %2d columns' %(SabSoil_df.shape[0], SabSoil_df.shape[1]))
print('Southern Soil\'s dataset has %2d rows and %2d columns' %(SouSoil_df.shape[0], SouSoil_df.shape[1]))
Sabaragamuwa's Soil dataset has  2 rows and  3 columns
Southern Soil's dataset has  2 rows and  3 columns
In [ ]:
# Using pandas to concatenate the dataframes.
regionsSoil_df = pd.concat([SabSoil_df, SouSoil_df], ignore_index=True)
# Plotting in the maps
fig, axes = plt.subplots(1,3, figsize=(20,50))

# first map axes[0]
axes[0].set_title('SOIL RESOURCES - REGION VIEW\n', fontsize=20)
boundary_df.plot(ax=axes[0], color='lightgreen', edgecolor='black')
regionsSoil_df.plot(ax=axes[0], column='ipcc', cmap='Set1', edgecolor='black',
                    legend=True, legend_kwds={'loc': 'lower left'})

# second map axes[1]
axes[1].set_title('SOIL RESOURCES IN Southern\n', fontsize=20)
SouSoil_df.plot(ax=axes[1], column='ipcc', cmap='Set1', edgecolor='black',
                  legend=True, legend_kwds={'loc': 'lower left'})

# third map axes[2]
axes[2].set_title('SOIL RESOURCES IN Sabaragamuwa\n', fontsize=20)
SabSoil_df.plot(ax=axes[2], column='ipcc', cmap='Set1', edgecolor='black',
                  legend=True, legend_kwds={'loc': 'upper right'})

plt.show()